import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.event.*;

import java.util.*;
import java.io.*;
public class DetailSideBar extends JPanel implements ItemListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4813523861439431045L;
	JPanel dataType;
	JPanel purpose;
	JPanel recipient;
	
	JCheckBox physical,online,state,uniqueid,demographic,financial,health,preference,
	purchase,government,political,interactive,content,computer,navigation,location;
	
	JCheckBox current,admin,develop,tailoring,historical,contact,telemarketing,pseAnalysis,
	pseDecision,indAnalysis,indDecision;
	
	JCheckBox ours,delivery,same,otherRecip,unrelated,publicForum;
	
	public DetailSideBar(){
		super();
		
		physical = new JCheckBox("physical");
		online = new JCheckBox("online");
		state = new JCheckBox("state");
		uniqueid = new JCheckBox("uniqueid");
		demographic = new JCheckBox("demographic");
		financial = new JCheckBox("financial");
		health = new JCheckBox("health");
		preference = new JCheckBox("preference");
		purchase = new JCheckBox("purchase");
		government = new JCheckBox("government");
		political = new JCheckBox("political");
		interactive = new JCheckBox("interactive");
		content = new JCheckBox("content");
		computer = new JCheckBox("computer");
		navigation = new JCheckBox("navigation");
		location = new JCheckBox("location");
		
		current = new JCheckBox("current");
		admin = new JCheckBox("admin");
		develop = new JCheckBox("develop");
		tailoring = new JCheckBox("tailoring");
		historical = new JCheckBox("historical");
		contact = new JCheckBox("contact");
		telemarketing = new JCheckBox("telemarketing");
		pseAnalysis = new JCheckBox("pseudo-analysis");
		pseDecision = new JCheckBox("pseudo-decision");
		indAnalysis = new JCheckBox("individual-analysis");
		indDecision = new JCheckBox("individual-decision");
		
		ours = new JCheckBox("ours");
		delivery = new JCheckBox("delivery");
		same = new JCheckBox("same");
		otherRecip = new JCheckBox("other-recipient");
		unrelated = new JCheckBox("unrelated");
		publicForum = new JCheckBox("public");
		
		/***************************************/
		physical.addItemListener(this);
		online.addItemListener(this);
		state.addItemListener(this);
		uniqueid.addItemListener(this);
		demographic.addItemListener(this);
		financial.addItemListener(this);
		health.addItemListener(this);
		preference.addItemListener(this);
		purchase.addItemListener(this);
		government.addItemListener(this);
		political.addItemListener(this);
		interactive.addItemListener(this);
		content.addItemListener(this);
		computer.addItemListener(this);
		navigation.addItemListener(this);
		location.addItemListener(this);
		
		current.addItemListener(this);
		admin.addItemListener(this);
		develop.addItemListener(this);
		tailoring.addItemListener(this);
		historical.addItemListener(this);
		contact.addItemListener(this);
		telemarketing.addItemListener(this);
		pseAnalysis.addItemListener(this);
		pseDecision.addItemListener(this);
		indAnalysis.addItemListener(this);
		indDecision.addItemListener(this);
		
		ours.addItemListener(this);
		delivery.addItemListener(this);
		same.addItemListener(this);
		otherRecip.addItemListener(this);
		unrelated.addItemListener(this);
		publicForum.addItemListener(this);
		/***************************************/
		
		JPanel contactP=new JPanel(new GridLayout(2,1));
		contactP.add(physical);
		contactP.add(online);
		JPanel cookieP=new JPanel(new GridLayout(2,1));
		cookieP.add(state);
		cookieP.add(uniqueid);
		JPanel demographicP=new JPanel(new GridLayout(1,1));
		demographicP.add(demographic);
		JPanel financialP=new JPanel(new GridLayout(1,1));
		financialP.add(financial);
		JPanel healthP=new JPanel(new GridLayout(1,1));
		healthP.add(health);
		JPanel preferenceP=new JPanel(new GridLayout(1,1));
		preferenceP.add(preference);
		JPanel purchaseP=new JPanel(new GridLayout(1,1));
		purchaseP.add(purchase);
		JPanel socialP=new JPanel(new GridLayout(2,1));
		socialP.add(government);
		socialP.add(political);
		JPanel activityP=new JPanel(new GridLayout(4,1));
		activityP.add(interactive);
		activityP.add(content);
		activityP.add(computer);
		activityP.add(navigation);
		JPanel locationP=new JPanel(new GridLayout(1,1));
		locationP.add(location);
		
		dataType=new JPanel(new CardLayout());
		dataType.add(new JPanel(),"space");
		dataType.add(contactP,"1");
		dataType.add(cookieP,"2");
		dataType.add(demographicP,"3");
		dataType.add(financialP,"4");
		dataType.add(healthP,"5");
		dataType.add(preferenceP,"6");
		dataType.add(purchaseP,"7");
		dataType.add(socialP,"8");
		dataType.add(activityP,"9");
		dataType.add(locationP,"10");
		
		JLabel dataL=new JLabel("<html><body><br> Data Category:</body></html>");
		JPanel dataP1=new JPanel(new BorderLayout());
		dataP1.add(dataL,"North");
		dataP1.add(dataType,"Center");
		JPanel dataP=new JPanel(new BorderLayout());
		dataP.add(dataP1,"North");
		dataP.add(new JSeparator(),"South");
		/***************************************/
		JPanel serviceP = new JPanel(new GridLayout(5,1));
		serviceP.add(current);
		serviceP.add(admin);
		serviceP.add(develop);
		serviceP.add(tailoring);
		serviceP.add(historical);
		JPanel marketP = new JPanel(new GridLayout(1,1));
		marketP.add(contact);
		JPanel telemarketP = new JPanel(new GridLayout(1,1));
		telemarketP.add(telemarketing);
		JPanel profileP = new JPanel(new GridLayout(4,1));
		profileP.add(pseAnalysis);
		profileP.add(pseDecision);
		profileP.add(indAnalysis);
		profileP.add(indDecision);
		
		purpose=new JPanel(new CardLayout());
		purpose.add(new JPanel(),"space");
		purpose.add(serviceP,"2");
		purpose.add(marketP,"3");
		purpose.add(telemarketP,"4");
		purpose.add(profileP,"5");
		JLabel purposeL=new JLabel("<html><body><br> Purpose:</body></html>");
		JPanel purposeP1=new JPanel(new BorderLayout());
		purposeP1.add(purposeL,"North");
		purposeP1.add(purpose,"Center");
		JPanel purposeP=new JPanel(new BorderLayout());
		purposeP.add(purposeP1,"North");
		purposeP.add(new JSeparator(),"South");
		
		/***************************************/
		JPanel companyP=new JPanel(new GridLayout(5,1)); 
		companyP.add(ours);
		companyP.add(delivery);
		companyP.add(same);
		companyP.add(otherRecip);
		companyP.add(unrelated);
		JPanel publicP=new JPanel(new GridLayout(1,1));
		publicP.add(publicForum);
		
		recipient=new JPanel(new CardLayout());
		recipient.add(new JPanel(),"space");
		recipient.add(companyP,"7");
		recipient.add(publicP,"8");
		JLabel recipientL=new JLabel("<html><body><br> Recipient:</body></html>");
		JPanel recipientP1=new JPanel(new BorderLayout());
		recipientP1.add(recipientL,"North");
		recipientP1.add(recipient,"Center");
		JPanel recipientP=new JPanel(new BorderLayout());
		recipientP.add(recipientP1,"North");
		/***************************************/		
		setLayout(new GridLayout(3,1));
		add(dataP);
		add(purposeP);
		add(recipientP);
		
	}
	
	public void refresh(Detail d){
		physical.setSelected(d.bool[0]);
		online.setSelected(d.bool[1]);
		state.setSelected(d.bool[2]);
		uniqueid.setSelected(d.bool[3]);
		demographic.setSelected(d.bool[4]);
		financial.setSelected(d.bool[5]);
		health.setSelected(d.bool[6]);
		preference.setSelected(d.bool[7]);
		purchase.setSelected(d.bool[8]);
		government.setSelected(d.bool[9]);
		political.setSelected(d.bool[10]);
		interactive.setSelected(d.bool[11]);
		content.setSelected(d.bool[12]);
		computer.setSelected(d.bool[13]);
		navigation.setSelected(d.bool[14]);
		location.setSelected(d.bool[15]);
		
		current.setSelected(d.bool[16]);
		admin.setSelected(d.bool[17]);
		develop.setSelected(d.bool[18]);
		tailoring.setSelected(d.bool[19]);
		historical.setSelected(d.bool[20]);
		contact.setSelected(d.bool[21]);
		telemarketing.setSelected(d.bool[22]);
		pseAnalysis.setSelected(d.bool[23]);
		pseDecision.setSelected(d.bool[24]);
		indAnalysis.setSelected(d.bool[25]);
		indDecision.setSelected(d.bool[26]);
		
		ours.setSelected(d.bool[27]);
		delivery.setSelected(d.bool[28]);
		same.setSelected(d.bool[29]);
		otherRecip.setSelected(d.bool[30]);
		unrelated.setSelected(d.bool[31]);
		publicForum.setSelected(d.bool[32]);
	}

	@Override
	public void itemStateChanged(ItemEvent e) {
		// TODO Auto-generated method stub
		int i=MainFrame.getInstance().tabPan.getSelectedIndex();
		int j=MainFrame.getInstance().policies.get(i).nutrition.tab.getSelectedIndex();
		NutritionTableView view=MainFrame.getInstance().policies.get(i).nutrition.tables.get(j);
		int row=view.table.getSelectedRow();
		int col=view.table.getSelectedColumn();
		Detail d=view.detail[row][col];
		if(e.getSource().equals(physical))
		d.set(0, physical.isSelected());
		if(e.getSource().equals(online))
		d.set(1, online.isSelected());
		if(e.getSource().equals(state))
		d.set(2, state.isSelected());
		if(e.getSource().equals(uniqueid))
		d.set(3, uniqueid.isSelected());
		if(e.getSource().equals(demographic))
		d.set(4, demographic.isSelected());
		if(e.getSource().equals(financial))
		d.set(5, financial.isSelected());
		if(e.getSource().equals(health))
		d.set(6, health.isSelected());
		if(e.getSource().equals(preference))
		d.set(7, preference.isSelected());
		if(e.getSource().equals(purchase))
		d.set(8, purchase.isSelected());
		if(e.getSource().equals(government))
		d.set(9, government.isSelected());
		if(e.getSource().equals(political))
		d.set(10, political.isSelected());
		if(e.getSource().equals(interactive))
		d.set(11, interactive.isSelected());
		if(e.getSource().equals(content))
		d.set(12, content.isSelected());
		if(e.getSource().equals(computer))
		d.set(13, computer.isSelected());
		if(e.getSource().equals(navigation))
		d.set(14, navigation.isSelected());
		if(e.getSource().equals(location))
		d.set(15, location.isSelected());
		
		if(e.getSource().equals(current))
		d.set(16, current.isSelected());
		if(e.getSource().equals(admin))
		d.set(17, admin.isSelected());
		if(e.getSource().equals(develop))
		d.set(18, develop.isSelected());
		if(e.getSource().equals(tailoring))
		d.set(19, tailoring.isSelected());
		if(e.getSource().equals(historical))
		d.set(20, historical.isSelected());
		if(e.getSource().equals(contact))
		d.set(21, contact.isSelected());
		if(e.getSource().equals(telemarketing))
		d.set(22, telemarketing.isSelected());
		if(e.getSource().equals(pseAnalysis))
		d.set(23, pseAnalysis.isSelected());
		if(e.getSource().equals(pseDecision))
		d.set(24, pseDecision.isSelected());
		if(e.getSource().equals(indAnalysis))
		d.set(25, indAnalysis.isSelected());
		if(e.getSource().equals(indDecision))
		d.set(26, indDecision.isSelected());
		
		if(e.getSource().equals(ours))
		d.set(27, ours.isSelected());
		if(e.getSource().equals(delivery))
		d.set(28, delivery.isSelected());
		if(e.getSource().equals(same))
		d.set(29, same.isSelected());
		if(e.getSource().equals(otherRecip))
		d.set(30, otherRecip.isSelected());
		if(e.getSource().equals(unrelated))
		d.set(31, unrelated.isSelected());
		if(e.getSource().equals(publicForum))
		d.set(32, publicForum.isSelected());
	}
}
